package workbench.actors;
import box2D.collision.shapes.B2CircleShape;
import box2D.common.math.B2Vec2;
import box2D.dynamics.B2Body;
import box2D.dynamics.B2BodyDef;
import box2D.dynamics.B2FixtureDef;
import box2D.dynamics.B2World;
import openfl.Assets;
import openfl.display.Bitmap;
import com.funkyfurrymonkey.constants.Convert;
import openfl.display.Sprite;
/**
 * ...
 * @author Marcos Martinez
 */
class DummyBall
{
	public var m_cCanvas:Sprite;
	private var m_nRatio:Float = 1.0;
	private var b:B2Body;
	public function new(m_cWorld:B2World) 
	{
		var m_cCostume:Bitmap = new Bitmap(Assets.getBitmapData("img/hud_p1.png"));
		var m_physScale:Float = 1.0;
		m_cCanvas = new Sprite();
		m_cCostume.x = -m_cCostume.width / 2;
		m_cCostume.y = -m_cCostume.height / 2;
		m_cCanvas.addChild(m_cCostume);
		var cd:B2CircleShape = new B2CircleShape();
		cd.m_radius = (m_cCostume.width/2) / m_physScale;
		var fd:B2FixtureDef = new B2FixtureDef();
		fd.density = 2;
		fd.restitution = 0.2;
		fd.friction = 0.5;
		fd.shape = cd;
		var bd:B2BodyDef = new B2BodyDef();
		bd.type = 2;//B2Body.B2_dynamicBody;
		bd.userData = "ball";
		bd.position.set( (50 ) / m_physScale, (100 ) / m_physScale);
			
		b = m_cWorld.createBody(bd);
		b.createFixture(fd);
			
		var nX :Float = 100.0;
		var nY:Float = 1.0;
			
		var nVelX :Float = 100.0;
		var nVelY:Float = 1.0;
			
			
		
		var startingVelocity:B2Vec2 = new B2Vec2(nVelX, nVelY);
		b.m_force = new B2Vec2(100, 100);
		b.setLinearVelocity(startingVelocity);
		b.applyImpulse(new B2Vec2(nX, -1 * nY), b.getWorldCenter());
		b.setPosition(new B2Vec2(nX, nY));
		
		
		updateMyLook();
	}
	
	public function updateMyLook() 
	{
	
		m_cCanvas.x = b.getPosition().x * m_nRatio ;// - m_cCostume.width / 2;
		m_cCanvas.y = b.getPosition().y * m_nRatio;// -m_cCostume.height / 2;
		
		m_cCanvas.rotation = b.getAngle()  * Convert.RADIANS_TO_DEGREES;
	}
	
}